package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.system.domain.ScodeSmallEty;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ScodeSmallDao extends BaseMapper<ScodeSmallEty> {
    /**
     * 交办意见列表数据
     * @param scodeSmallEty
     * @return
     */
    @Select("select CSValue,CSText,CSOrd from sCodeSmall WHERE codeBig='opinion' AND useFlag=1  AND isDel=0 [[and CSText =#{cstext}]]")
    List<ScodeSmallEty> xdealDescJson(ScodeSmallEty scodeSmallEty);

    /**
     * 交办意见 根据 csvalue 单个删除和多选删除
     * @param ids
     * @return
     */
    @Update("<script>" +
            "UPDATE sCodeSmall SET IsDel=1,useFlag=0 WHERE codeBig='opinion' AND useFlag=1 and  CSValue IN " +
            "<foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach>"
            + "</script>")
    int deleteByIds(String[] ids);

    /**
     * 根据 csvalue 查询交办意见
     * @param csvalue
     * @return
     */
    @Select("select CSValue,CSText,codeBig,CSOrd,UseFlag from sCodeSmall WHERE CSValue=#{csvalue} AND  codeBig='opinion' AND useFlag=1  AND isDel=0")
    ScodeSmallEty selectCsValue(@Param("csvalue") String csvalue);

    /**
     *
     * @return
     */
    @Select("select CSOrd from sCodeSmall WHERE  codeBig='opinion' AND useFlag=1  AND isDel=0")
    List<Integer> getCSOrd();

    /**
     * <h3>查询常用语管理列表数据<h3/>
     * <p>常用语:电话交办意见、坐席备注，信件处理意见</p>
     * @param scodeSmallEty 查询条件
     * @return 列表数据
     */
    @Select("select id,CSValue,CSText,codeBig,Type,CSOrd,UseFlag,Remark from sCodeSmall WHERE isDel = 0 and useFlag = 1 " +
            "and codeBig in('opinion','SeatsRemark','opinionM') [[and codeBig = #{codeBig}]]" +
            "[[and CSText =#{cstext}]] [[and type =#{type}]]")
    List<ScodeSmallEty> scodeSmallListJson(ScodeSmallEty scodeSmallEty);
}
